/*
 * @Author: czy
 * @Date: 2021-04-24 08:15:19
 * @LastEditTime: 2021-05-21 22:22:28
 */
#include "string.h"
#include "vsprintf.h"
#include "datetime.h"

#include "api/system.h"

static char format[40] = "%Y/%m/%d %H:%M:%S";

/**
 * @description: Display wall clock.
 */
void showWallClock(void)
{
    char temp[40] = "";
    time_t time = gettime();
    tm t_time;
    localtime(&time, &t_time);
    strftime(temp, format, t_time);
    char str[50] = "";
    sprintf(str, "\033[32m%s\033[0m", temp);
    gotoxy(80 - strlen(temp), 24, str, 0);
}

/**
 * @description: Set WallClock display format.
 * @param fmt   Format.
 */
void setWallClockFormat(char *fmt)
{
    strcpy(format, fmt);
}

/**
 * @description: Set the WallClock refresh period.
 * @param interval  Refresh interval.
 */
void setWallClockRefresh(int interval)
{
    timer(showWallClock, interval);
}
